package mobi.greenplate.client.converter;

import mobi.greenplate.client.domain.UserDetail;
import mobi.greenplate.client.domain.UserType;

/**
 *
 * @author dmakariev
 */
public class UserDetailConverter {
    /*
     *      <userDetail>
     *          <email>testuser@mailinator.com</email>
     *          <firstName>testFirst</firstName>
     *          <id>3</id>
     *          <lastName>testLast</lastName>
     *          <owner>
     *              <id>1</id>
     *              <password>5d9c68c6c50ed3d02a2fcf54f63993b6</password>
     *              <type>agency</type>
     *              <userName>testuser</userName>
     *              <userRole>ROLE_USER</userRole>
     *          </owner>
     *          <phone>666445656</phone>
     *          <type>individual</type>
     *      </userDetail>
     */

    private UserDetailConverter() {
    }
    private static final String ID = "id";
    private static final String EMAIL = "email";
    private static final String FIRST_NAME = "firstName";
    private static final String LAST_NAME = "lastName";
    private static final String PHONE = "phone";
    private static final String TYPE = "type";

    public static UserDetail endTag(UserDetail userDetail, String tagName, String text) {
        if (tagName.equalsIgnoreCase(ID)) {
            userDetail.setId(Long.valueOf(text));
        } else if (tagName.equalsIgnoreCase(EMAIL)) {
            userDetail.setEmail(text);
        } else if (tagName.equalsIgnoreCase(FIRST_NAME)) {
            userDetail.setFirstName(text);
        } else if (tagName.equalsIgnoreCase(LAST_NAME)) {
            userDetail.setLastName(text);
        } else if (tagName.equalsIgnoreCase(TYPE)) {
            userDetail.setType(UserType.valueOf(text));
        } else if (tagName.equalsIgnoreCase(PHONE)) {
            userDetail.setPhone(text);
        }
        return userDetail;
    }
}
